//
//  MACountListViewController.m
//  meiang_edu
//
//  Created by 栋 on 2019/1/8.
//  Copyright © 2019年 com.meiang.meiang_edu. All rights reserved.
//

#import "MACountListViewController.h"
#import "MACompleteStatusCell.h"
@interface MACountListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation MACountListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setUpTableView];
}

- (void)setDataSource:(NSArray *)dataSource{
    _dataSource = [dataSource copy];
    [self.tableView reloadData];
}

- (void)setUpTableView{
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.rowHeight = 76;
    [self.tableView registerNib:[UINib nibWithNibName:@"MACompleteStatusCell" bundle:nil] forCellReuseIdentifier:@"MACompleteStatusCell"];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
}

- (void)loadData{
    WS(weakSelf)
    [self.parentVC loadDataWithCompleteBlock:^{
        [weakSelf.tableView.mj_header endRefreshing];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MACompleteStatusCell * cell =[tableView dequeueReusableCellWithIdentifier:@"MACompleteStatusCell" forIndexPath:indexPath];
    if ([self.parentVC.model.message_type isEqualToString:@"活动"]) {
        cell.imgStatus.hidden = YES;
        cell.lblStatus.hidden = YES;
    } else if (_finishType==MACountListViewFinishTypeFinished) {
        cell.imgStatus.image = [UIImage imageNamed:@"notice_finished"];
        cell.lblStatus.hidden = YES;
    }else{
        cell.imgStatus.image = [UIImage imageNamed:@"notice_unfinished"];
        cell.lblStatus.hidden = NO;
    }
    
    [cell setDataWithModel:self.dataSource[indexPath.row] indexPath:indexPath];
    return cell;
}


@end
